import dayjs from 'dayjs'

import calendar from 'dayjs/plugin/calendar'

import localeData from 'dayjs/plugin/localeData'

import relativeTime from 'dayjs/plugin/relativeTime'
import updateLocale from 'dayjs/plugin/updateLocale'
import weekday from 'dayjs/plugin/weekday'
import { createSSRApp } from 'vue'
import { pinia } from '@/stores'

import uvUI from '@/uni_modules/uv-ui-tools'

import App from './App.vue'
import { prototypeInterceptor, routeInterceptor } from './interceptors'

import 'uno.css'

import 'dayjs/locale/zh-cn'

dayjs.extend(localeData)
dayjs.extend(weekday)
dayjs.extend(calendar)
dayjs.extend(relativeTime)
dayjs.extend(updateLocale)
dayjs.locale('zh-cn')
dayjs.updateLocale('zh-cn', {
  relativeTime: {
    future: '刚刚',
    past: '%s前',
    s: '几秒',
    m: '1 分钟',
    mm: '%d 分钟',
    h: '1 小时',
    hh: '%d 小时',
    d: '1 天',
    dd: '%d 天',
    M: '1 个月',
    MM: '%d 个月',
    y: '1 年',
    yy: '%d 年',
  },
  calendar: {
    lastDay: '昨天',
    sameDay: '今天',
    nextDay: '明天',
    lastWeek: '上周dddd',
    nextWeek: 'dddd',
    sameElse: 'YYYY-MM-DD',
  },
})

uni.$zp = {
  config: {
    'safe-area-inset-bottom': true,
    'auto-show-back-to-top': true,
    'back-to-top-bottom': '350rpx',
    'inside-more': true,
  },
}

export function createApp() {
  const app = createSSRApp(App)

  app.use(pinia)
  app.use(uvUI, { mpShare: true })
  app.use(routeInterceptor)
  app.use(prototypeInterceptor)

  return {
    app,
  }
}
